package Lee_code;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author blh
 * @date 2024年07月17日 20:44
 */
public class Lee_179_717 {
    public String largestNumber(int[] nums) {
        int len = nums.length;
        List<Integer> list = Arrays.stream(nums).boxed().sorted(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                String str1 = o1.toString() + o2.toString();
                String str2 = o2 + o1.toString();
                BigInteger bigInt1 = new BigInteger(str1);
                BigInteger bigInt2 = new BigInteger(str2);

                return bigInt2.compareTo(bigInt1);
            }
        }).collect(Collectors.toList());
        StringBuilder sb = new StringBuilder();
        for (Integer i : list) {
            sb.append(i);
        }
        return sb.charAt(0)=='0'? "0":sb.toString();
    }
}
